<!-- 技术评估 -->
<template>
  <div>
    <Card :bordered="false">
      <p slot="title">技术评估</p>
      <!-- 99%改成100 -->
      <table id="pgb" width='100%' border="1" cellspacing="0" cellpadding="0" ref="print">
        <tr>
          <th colspan="4">
            技术评估表
          </th>
        </tr>
        <tr>
          <td width="25%">
            项目名称</td>
          <td colspan="3" class="sizeStyle">
            {{info.ProjectName}}
            <Icon type="ios-arrow-down" size='15' style="cursor:pointer" @click="viewClick($event,'projectName')" v-if='projectNameList.length>0'/>
            <Oldname v-if="projectName" :oldName="projectNameList"></Oldname>
            <!-- <Input v-model="info.Project_name" /> -->
          </td>
        </tr>
        <tr>
          <td width="25%">项目编号</td>
          <td colspan="3" class="sizeStyle">
            {{info.ProjectNumber}}
          </td>
        </tr>
        <tr>
          <td width="25%">建设单位</td>
          <td colspan="3">
            <Input v-model="info.BuildUnit" :disabled='viewOnly'/>
            <Icon type="ios-arrow-down" size='15' style="cursor:pointer" @click="viewClick($event,'buildName')" v-if='buildNameList.length>0'/>
            <Oldname v-if="buildName" :oldName="buildNameList"></Oldname>
          </td>
        </tr>
        <tr>
          <td width="25%">建设地点</td>
          <td colspan="3" class="sizeStyle">
            {{info.BuildAddress}}
            <!-- <Input v-model="info.Build_address" /> -->
          </td>
        </tr>
        <tr>
          <td width="25%">报告类型</td>
          <td colspan="3" class="sizeStyle">
            {{info.ReportType}}
            <!-- <Input v-model="info.Report_type" /> -->
          </td>
        </tr>
        <tr>
          <td width="25%">技术评估时间</td>
          <td width="25%">
           <Input v-model="info.AppraiseDate" :disabled='viewOnly'/>
            <!-- <p v-show="istime" v-show="!istime">{{info.Appraise_date}}</p> -->
          </td>
          <td width="25%">
            技术评估会议地点
          </td>
          <td width="25%">
            <Input type="textarea" v-model="info.AppraiseAddress" :disabled='viewOnly'/>
          </td>
        </tr>
        <tr>
          <td>
            评估专家
          </td>
          <td colspan="3">
            <Input v-model="info.AppraisePerson" :disabled='viewOnly'/>
          </td>
        </tr>
        <tr>
          <td width="25%" rowspan="2">
            评估意见
          </td>
          <td colspan="3">
            <!-- 99%改成100% -->
            <div style="width:100%;margin:auto;height:100%;">
              <Table border ref="selection" style="border: none" :columns="appraiseListsOption" :data="appraiseList"></Table>
            </div>
            <Row>
              <Col span="24" style="text-align: center;padding:10px">
              <Button type="primary" @click="inputAdd('appraiseList')" :disabled='viewOnly'>添加</Button>
              <Button type="error" @click="inputRe('appraiseList')" :disabled='viewOnly'>删除</Button>
              </Col>
            </Row>
          </td>
        </tr>
        <tr>
          <td>
            专家评估意见
          </td>
          <td colspan="2">
            <Col span="12"><UploadFile v-model="info.AppraiseData" :upName="AppraiseData" UploadFileName="AppraiseData" :UploadFileId="$route.query.ProjectId" :isDisabled='viewOnly'/></Col>
            <Col span="12"><DownloadButton v-if="viewOnly" :downData="downloadInfo.AppraiseData"></DownloadButton></Col>
            <span style="font-size:12px;color:#666;line-height:32px;">上传专家意见和专家签名表，上传文件格式为docx、doc、PDF、图片</span>
          </td>
        </tr>
        <tr>
          <td>
            评估意见修改单
          </td>
          <td colspan="3">
            <div style="width:100%;margin:auto;height:100%;">
              <Table border style="border: none" :columns="appraiseListsOptionXg" :data="appraiseListXg"></Table>
            </div>

          </td>
        </tr>
        <tr>
          <td>
            修改后报告
          </td>
          <td colspan="3" style="padding:20px">
            <Col span="12"><UploadFile v-model="info.ReportChange" :upName="ReportChange" UploadFileName="ReportChange" :UploadFileId="$route.query.ProjectId" :isDisabled='viewOnly'/></Col>
            <Col span="12"><DownloadButton v-if="viewOnly" :downData="downloadInfo.ReportChange"></DownloadButton></Col>
            <span  style="font-size:12px;color:#666;line-height:32px;">上传专家意见和专家签名表，上传文件格式为docx、doc、PDF、图片</span>
            
          </td>
        </tr>
      </table>
      <Row style="padding:20px 0">
        <Col span="4">
        <!-- <Button type="primary" @click="print">打印</Button> -->
        <PrintButton v-if="flag" Url="print/printAppraise" :Project_id="info.Id"></PrintButton>
        </Col>
        <Col span="20" style="text-align:right">
        <Button type="primary" @click="submit('save')" :disabled='viewOnly'>保存</Button>
        <Button type="primary" @click="submit('submit')" :disabled='viewOnly'>提交报批</Button>
        </Col>
      </Row>
      <StepBar :status="6" :viewOnly='viewOnly'/>
    </Card>
    <!-- <Modal footer-hide v-model="modalPrint" title="请选择打印需求">
      <Row style="padding-bottom:30px">
        <Col span="12" style="text-align:center">
        <p>打印技术评估表</p>
        <PrintButton v-if="flag" Url="print/printAppraise" :Project_id="info.Id"></PrintButton>
        </Col>
        <Col span="12" style="text-align:center">
        <p>打印修改清单</p>
        <PrintButton v-if="flag" Url="print/printAppraiseChange" :Project_id="info.Id"></PrintButton>
        </Col>
      </Row>
    </Modal> -->
  </div>
</template>
<script>
  export default {
    data() {
      return {
        // 项目名称、建设单位、法人、联系人、联系电话留痕列表
        projectName: false,
        buildName: false,
        projectNameList: [], 
        buildNameList: [], 
        viewOnly: false,  // 允许查看
        AppraiseData: "",
        ReportChange: "",
        modalPrint: false,
        flag: false,
        value4: "",
        datatime: "",
        istime: false,
        downloadInfo: {},
        info: {},
        /* 专家意见 */
        appraiseListsOption: [{
            align: "center",
            width: 80,
            title: "序号",
            type: 'index'
          },
          {
            align: "center",
            title: "专家评估意见",
            key: "AppraiseOpinion",
            render: (h, {
              row,
              index
            }) => {
              return h("Input", {
                props: {
                  type: "textarea",
                  value: row.AppraiseOpinion,
                },
                on: {
                  "on-blur": val => {
                    this.appraiseList[index].AppraiseOpinion = val.target.value;
                    this.appraiseList[index]["ProjectId"] = this.$route.query.ProjectId || this.$route.query
                      .id;
                    this.appraiseListXg = []
                    this.$nextTick(()=>{
                      this.appraiseListXg = this.appraiseList
                    })
                    console.log(this.appraiseListXg)
                  }
                }
              });
            }
          }
        ],
        appraiseList: [],
        /* 专家修改意见 */
        appraiseListsOptionXg: [{
            align: "center",
            width: 80,
            title: "序号",
            type: 'index'
          },
          {
            align: "center",
            title: "专家评估意见",
            key: "AppraiseOpinion",
            // render: (h, {
            //   row,
            //   index
            // }) => {
            //   return h("Input", {
            //     props: {
            //       type: "text",
            //       value: row.Appraise_opinion
            //     },
            //     on: {
            //       "on-blur": val => {
            //         this.appraiseListXg[index].Appraise_opinion = val.target.value;
            //         this.appraiseListXg[index][
            //           "Project_id"
            //         ] = this.$route.query.Project_id || this.$route.query.id;
            //       }
            //     }
            //   });
            // }
          },
          {
            align: "center",
            title: "修改说明",
            key: "ReviseExplain",
            render: (h, {
              row,
              index
            }) => {
              return h("Input", {
                props: {
                  type: "textarea",
                  value: row.ReviseExplain
                },
                on: {
                  "on-blur": val => {
                    this.appraiseListXg[index].ReviseExplain = val.target.value;
                  }
                }
              });
            }
          },
        ],
        appraiseListXg: [],
        updatedInfo: 0,
        setButton: 0,
      };
    },
    created() {
      // let query = this.$route.query
      // this.query = query
      // this.getProject(this.query.id)
      //判断是否有ID
      if (this.$route.query.ProjectId && this.$route.query.ProjectId != "") {
        let query = this.$route.query
        this.query = query
        this.getProject(this.$route.query.ProjectId);
        if(this.$route.query.viewOnly==1 || localStorage.getItem('userOrg') ==7) {
          this.viewOnly = true
        }
      } else {
        //跳转首页
        this.$router.push({
          name: "index"
        });
      }
    },
    methods: {
      // 名字去重显示
      viewClick(e,nameShow) {
        if(!this[nameShow]) {
          e.target.className = 'ivu-icon ivu-icon-ios-arrow-up'
        }else {
          e.target.className = 'ivu-icon ivu-icon-ios-arrow-down'
        }
        this[nameShow] = !this[nameShow]
      },
      time1(e){
        this.info.AppraiseDate = e;
        console.log(this.info.AppraiseDate)
      },
      print() {
        // this.modalPrint = true
      },
      //点击添加意见
      inputAdd(type) {
        // this.appraiseListXg = []
        this[type].push({AuditTime:new Date().getTime()})
      },
      //点击删除意见
      inputRe(type){
        this[type].pop()
        console.log(type);
      },
      // 意见发送
      appraiseListFn() {
        let appraiseList = this.appraiseList;
        axios.post("appraise/saveOrUpdate", {
          appraiseList:JSON.stringify(appraiseList)
        }).then(res => {}).catch(err => {
          // alert('发送意见失败')
          this.$Message.error('发送意见失败')
        })
      },
      /* 获取当前创建项目 */
      getProject(Id) {
        this.$post('ProjectInfo.findProjectByID', {
            Id: Id || this.$route.query.ProjectId
        }).then(res => {
          this.downloadInfo = res.doc
          this.info = res.info
          // console.log(this.info)
          // 项目名字留痕
          if(res.pt2List.length>0) {
            var arrAll = res.pt2List //所有更改记录
            function arrayUnique2(arr, ProjectName) {
              var hash = {};
              return arr.reduce(function (item, next) {
                hash[next[ProjectName]] ? '' : hash[next[ProjectName]] = true && item.push(next);
                return item;
              }, []);
            }
            var projectNameList = arrayUnique2(arrAll, "ProjectName")
            if(projectNameList[0].ProjectName==this.info.ProjectName) {
              projectNameList = arrayUnique2(arrAll, "ProjectName").slice(1)
            }
            projectNameList.forEach(e => {
              this.projectNameList.push({name: e.ProjectName,Operator: e.Operator,UpdateTime: e.UpdateTime})
            });

            var buildNameList = arrayUnique2(arrAll, "BuildUnit")
            if(buildNameList[0].BuildUnit==this.info.BuildUnit) {
              buildNameList = arrayUnique2(arrAll, "BuildUnit").slice(1)
            }
            buildNameList.forEach(e => {
              this.buildNameList.push({name: e.BuildUnit,Operator: e.Operator,UpdateTime: e.UpdateTime})
            });          
          }
          
          if(this.info.AuditDate == ""){
            this.istime = false
          }else{
            this.istime = true
          }
          console.log(this.istime)
          this.appraiseList = res.appraiseList
          this.appraiseListXg = res.appraiseList
          localStorage.projectType = this.info.PerjectType
          this.flag = true
          this.AppraiseData = this.upWord(res.doc.AppraiseData)
          this.ReportChange = this.upWord(res.doc.ReportChange)
        }).catch(err => {
          console.log(err)
          this.$Message.error('获取当前项目失败！')
          // alert('请求崩溃1231')
        })
      },
      submit(type) {
        let info = this.info
        let appraiseListXg = this.appraiseListXg
        let appraiseList = this.appraiseList
        info.BtnWay = type == 'save' ? 1 : 2
        info.PerjectType = type == 'save' ? 12 : 12
        if(type == 'save'){
          if(this.setButton == 0){
            for(var keys=0;keys<this.appraiseList.length;keys++){
              let nRong = this.appraiseList[keys].AppraiseOpinion;
              if(nRong==""||nRong==null){
                // console.log(nRong);
                this.appraiseList.splice(keys,1);
              }
            }
            this.appraiseListFn()
            this.setButton = 1
            setTimeout(()=>{this.setButton = 0},60000)
            axios.post('/projectInformation/saveOrUpdateProject', info).then((res) => {
              if (res._STATUS == 1) {
                let title = res._MESSAGE
                if (type == 'save') {
                  this.$Modal.success({
                    title,
                  })
                } else {
                //   if(this.info.Perject_type == 12){
                //   axios.get('member/findByMembers').then((res)=>{
                //     var members = res.members
                //     console.log(members)
                //     social({
                //       method: 'post',
                //       url: '/info/notice',
                //       params: {
                //         content: this.info.Project_name + '项目已提交报批，请查阅项目技术评估情况，并关注项目报批事宜！',
                //         app_name: '环评管控系统',
                //         app: 'eao',
                //         type: members,
                //         uid: -1
                //       },
                //     }).then((res)=>{console.log(res)})
                //   })
                // }
                  this.$router.push({
                    name: "reportApproval",
                    query: {
                      ProjectId: this.$route.query.ProjectId
                    }
                  })
                }
              } else {
                this.$Modal.error({title:res._MESSAGE})
              }
            }).catch(err => {
              this.$Message.error('请求失败!')
            })
          }else{
            this.$Message.warning('连续点击保存时间过短，最少间隔1分钟!')
          }
        }else{
          if(this.updatedInfo == 0){
            this.appraiseListFn()
            this.updatedInfo = 1
            setTimeout(()=>{this.updatedInfo = 0},60000)
            axios.post('/projectInformation/saveOrUpdateProject', info).then((res) => {
              if (res._STATUS == 1) {
                let title = res._MESSAGE
                if (type == 'save') {
                  this.$Modal.success({
                    title,
                  })
                } else {
                  if(this.info.PerjectType == 12){
                  axios.get('member/findByMembers').then((res)=>{
                    var members = res.members
                    if(!(members==null||members=="")) {
                      console.log(this.info.ProjectName)
                      social({
                        method: 'post',
                        url: '/info/notice',
                        params: {
                          content: this.info.ProjectName + '项目已提交报批，请查阅项目技术评估情况，并关注项目报批事宜！',
                          app_name: '环评管控系统',
                          app: 'eao',
                          type: members,
                          uid: -1
                        },
                      }).then((res)=>{console.log(res)})
                    }
                  })
                }
                  this.$router.push({
                    name: "reportApproval",
                    query: {
                      ProjectId: this.$route.query.ProjectId
                    }
                  })
                }
              } else {
                this.$Modal.error({title:res._MESSAGE})
              }
            }).catch(err => {
              this.$Message.error('请求失败!')
            })
          }else{
            this.$Message.warning('连续点击提交时间过短，最少间隔1分钟!')
          }
        }

        // if(this.setButton == 0){
        //   this.setButton = 1
        //   setTimeout(()=>{this.setButton = 0},60000)
        
        // this.appraiseListFn()
        // let info = this.info
        // // if(this.updatedInfo <= 1){
        // //   this.$Message.warning('未修改数据无法提交')
        // //   return
        // // }
        // let appraiseListXg = this.appraiseListXg
        // let appraiseList = this.appraiseList
        // info.btn_way = type == 'save' ? 1 : 2
        // info.Perject_type = type == 'save' ? 12 : 12

        // axios.post('/projectInformation/saveOrUpdateProject', info).then((res) => {
        //   if (res._STATUS == 1) {

        //     let title = res._MESSAGE
        //     if (type == 'save') {
        //       this.$Modal.success({
        //         title,
        //       })
        //     } else {
        //       if(this.info.Perject_type == 12){
        //       axios.get('member/findByMembers').then((res)=>{
        //         var members = res.members
        //         console.log(members)
        //         social({
        //           method: 'post',
        //           url: '/info/notice',
        //           data: {
        //             content: this.info.Project_name + '项目已提交报批，请查阅项目技术评估情况，并关注项目报批事宜！',
        //             app_name: '环评管控系统',
        //             app: 'eao',
        //             type: members,
        //             uid: -1
        //           },
        //         }).then((res)=>{
        //           console.log(res)
        //         }).catch((err)=>{
        //           console.log(err)
        //         })
        //       }).catch((err)=>{
        //         console.log(err)
        //       })
        //     }
        //       this.$router.push({
        //         name: "reportApproval",
        //         query: {
        //           Project_id: this.$route.query.Project_id
        //         }
        //       })
        //     }
        //   } else {
        //     // 提示
        //     this.$Modal.error({
        //       title:res._MESSAGE
        //     })
        //   }
        // }).catch(err => {
        //   console.log(err)
        //   this.$Message.error('请求失败!')
        // })
        // }else{
        //   this.$Message.warning('请勿重复提交!')
        // }
      },
      upWord(url){        //分割字符串
        if(url == null){
          return '上传'
        }else{
          var upWord = url;
          upWord = upWord.split("/");
          upWord = upWord.slice(-1);
          upWord = upWord.join('');
          // console.log(upWord)
          return upWord
        }
      },
    },
  };
</script>
<style lang="less">
  #pgb {
    td.sizeStyle {
      font-size:12px;
    }
    textarea.ivu-input {
      font-size: 12px;
    }
    .ivu-input {
      border: none !important;
      text-align: center;
      height: 30px;

      input {
        outline: medium;
      }
    }
    .ivu-input[disabled], fieldset[disabled] .ivu-input {
      background-color: #fff; 
      color: #333;
      font-size: 12px;
    }
  }
</style>